# langchain_ollama的OllamaEmbeddings模型，示例

import ollama
from langchain_ollama import OllamaEmbeddings

model_name = "nomic-embed-text"

try:
    ollama.embed(model=model_name, input="Hello world!")
except ollama.ResponseError as e:
    print('Error:', e.error)
    if e.status_code == 404:
        print('Model not found, pulling from remote...')
        ollama.pull(model=model_name)

question = input("请输入问题：") or "20字介绍北京"

ollama_embeddings = OllamaEmbeddings(model=model_name)

# 计算文本的向量表示
vector = ollama_embeddings.embed_documents(question)

print(vector[0][:5])  # 打印第一个向量“2”表示的前5个元素
